package com.aoxin.controller.course.systemCourse;

import com.aoxin.model.course.SchoolCourse;
import com.aoxin.model.dto.SelectDto;
import com.aoxin.service.inter.course.systemCourse.SchoolCourseService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.Const;
import com.aoxin.util.enumerate.OperateType;
import com.aoxin.util.log.LogInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/web/system/")
public class SchoolCourseController {
    @Autowired
    private SchoolCourseService slfSchoolCourseService;
    /**
     * 查询某个学校课程
     * @param slfSchoolCourse
     * @return
     */
   // @LogInfo(operateType = OperateType.QUERY, content = "查询某个单独课程")
    @GetMapping("getSchoolCourse")
    public AjaxRes getSchoolCourse(SchoolCourse slfSchoolCourse, AjaxRes res) {
        try {
            List<SchoolCourse> schoolCourse = slfSchoolCourseService.getSchoolCourse(slfSchoolCourse);
            res.setSucceed(schoolCourse);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            res.setFailMsg("getSchoolCourse Failure!");
        }
        return res;
    }
    /**
     * 新增某个学校课程
     * @return
     */
   // @LogInfo(operateType = OperateType.INSERT, content = "新增某个学校的课程")
    @PostMapping("insertSchoolCourse")
    public AjaxRes insertSchoolCourse(@RequestParam(value = "courseIds")Integer courseId[], AjaxRes res) {
        try {
            Integer number = slfSchoolCourseService.insertSchoolCourse(courseId);
            res.setSucceed(number);
        } catch (Exception e) {
            res.setFailMsg(e.getMessage());
            e.printStackTrace();
        }
        return res;
    }

    /**
     * 修改某个学校课程
     * @param schoolCourse
     * @param res
     * @return
     */
    @LogInfo(operateType = OperateType.UPDATE,content = "修改某个学校课程")
    @PutMapping("updateSchoolCourse")
    public AjaxRes updateSchoolCourse(SchoolCourse schoolCourse, AjaxRes res){
        try{
            Integer integer = slfSchoolCourseService.updateSchoolCourse(schoolCourse);
            res.setSucceed(integer);
        }catch (Exception e){
            res.setFailMsg(e.getMessage());
            e.printStackTrace();
        }
        return res;
    }
    
    /**
     * 根据学校过滤的下拉树
     */
    @RequestMapping("getSchoolCourseListBySchool")
    public AjaxRes getSchoolCourseListBySchool(AjaxRes ajaxRes){
    	try{
    		List<SelectDto> selectDtos = this.slfSchoolCourseService.getListBySchool();
            ajaxRes.setSucceed(selectDtos,Const.DATA_SUCCEED);
        }catch (IllegalArgumentException e){
        	ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }

    /**
     * 查询课程包下的所有课程
     * @param schoolCoursePageId
     * @param ajaxRes
     * @return
     */
    @RequestMapping("getPageCourse")
    public AjaxRes getPageCourse(Integer schoolCoursePageId,AjaxRes ajaxRes){
        try {
            List<SchoolCourse> schoolCourseList = this.slfSchoolCourseService.getPageCourse(schoolCoursePageId);
            ajaxRes.setSucceed(schoolCourseList,Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
    @GetMapping("getSchoolCourseUser")
    public AjaxRes getSchoolCourseUser(SchoolCourse slfSchoolCourse, AjaxRes res) {
        try {
            List<SchoolCourse> schoolCourse = slfSchoolCourseService.getSchoolCourseUser(slfSchoolCourse);
            res.setSucceed(schoolCourse);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            res.setFailMsg("getSchoolCourse Failure!");
        }
        return res;
    }
}
